<include file="Public:header_content" />
<div class="col-sm-12">
    <!-- Example Events -->

    <div class="example-wrap">
        <h4 class="example-title"></h4>
        <div class="example">
            <table id="tableList"></table>
        </div>
    </div>
    <!-- End Example Events -->
</div>

<include file="Public:footer_content" />
<script src="/Public/plugin/gb312/js/bootstrap-table-edit.js"></script>
<script src="/Public/plugin/gb312/js/plugins/bootstrap-table/bootstrap-editable.js"></script>


<script type='text/javascript'>
    var tableList = $('#tableList');
    $(function () {
        tableList.bootstrapTable({
            url: "<{:U('Cate/getList')}>",
            refresh: {
                url: '<{:U("Cate/getList")}>',
                silent: false,
                //pageSize:2,
                query:{foo: 'bar'},
            },
            dataType:'json',
            method: 'post',
            contentType: "application/x-www-form-urlencoded",//post请求必带属性
            dataField: 'lists',
            //sortClass: 'cate_id',
            cache:true,
            showRefresh: true,
            showToggle: true,
            showPaginationSwitch: true,//显示分页按钮开关
            buttonsAlign: 'left',
            toolbarAlign: 'left',
            //showHeader: false,
            showFooter: true,
            showColumns: true,
            //cardView: true,
            //detailView: true,//rue to show detail view table.
            sortStable: true,

            paginationPreText: '上一页',
            paginationNextText: '下一页',
            iconSize: 'outline',
            idField:'cate_id',
            pagination: true, //分页
            //pageNumber: '2',//初始化到第几页
            pageSize: 20,//初始化页面条数
            pageList:[10,20,50],
            singleSelect: false,
            //data-locale:"zh-US", //表格汉化
            search: true, //显示搜索框
            searchAlign: 'right',
            sidePagination: "server", //server 服务端处理分页
            columns: [{
                field: 'checkbox',
                title: '',
                checkbox: true
            },{
                field: 'cate_id',
                title: 'ID',
                sortable: true,
                order:'asc',
                //visible: false, //影藏该字段
                align: 'center',
                valign: 'middle'
            }, {
                field: 'cate_name',
                title: '分类名称',
                align: 'center',
                valign: 'middle'
            },{
                field: 'alias',
                title: '分类别名',
                //clickToSelect: false,
                //switchable: false,
                align: 'center',
                valign: 'middle',
                editable: {
                    type: 'text',
                    url: function(params) {
                            //alert(JSON.stringify(params));
                            var d = new $.Deferred;
                            $.ajax({
                                type: "POST",
                                url: '<{:U("Cate/updateAlias")}>',
                                data: "alias="+params.value+'&cate_id='+params.pk,
                                success: function(msg){
                                    if(msg == 'success'){
                                        swal({title:"别名修改成功",text:"",type:"success"});
                                        return d.resolve();
                                    }else{
                                        swal("保存失败,请稍后在试","","error");
                                        //return d.resolve();
                                        return d.reject();
                                    }
                                }
                             });
                             return d.promise();
                        }
                },
                formatter: function (value, row,index) {
                    if(row.alias == null){
                        return '别名为空';
                    }
                    return row.alias;
                }
            },{
               field: 'is_view',
               title: '导航菜单',
               align: 'center',
               valign: 'middle',
               editable: {
                   title: "选择部门",           //编辑框的标题
                   disabled: false,           //是否禁用编辑
                   emptytext: "false",       //空值的默认文本
                   mode: "popup",            //编辑框的模式：支持popup和inline两种模式，默认是popup
                   type: 'select',
                   source: [
                       {value:'2',text:'显示'},
                       {value:'1',text:'不显示'}
                   ],
                   url: function(params) {
                           //alert(JSON.stringify(params));
                           var d = new $.Deferred;
                           $.ajax({
                               type: "POST",
                               url: '<{:U("Cate/updateOneField")}>',
                               data: "field=is_view&value="+params.value+'&id='+params.pk,
                               success: function(msg){
                                   if(msg == 'success'){
                                       swal({title:"别名修改成功",text:"",type:"success"});
                                       return d.resolve();
                                   }else{
                                       swal("保存失败,请稍后在试","","error");
                                       return d.reject();
                                   }
                               }
                            });
                            return d.promise();
                       }
               }
            },{
               field: 'tj_book',
               title: '推荐书籍',
               editable: {
                   title: "(填写书籍ID,多个用:分开)",           //编辑框的标题
                   disabled: false,           //是否禁用编辑
                   emptytext: "无",       //空值的默认文本
                   mode: "popup",            //编辑框的模式：支持popup和inline两种模式，默认是popup
                   type: 'text',
                   url: function(params) {
                           //alert(JSON.stringify(params));
                           var d = new $.Deferred;
                           $.ajax({
                               type: "POST",
                               url: '<{:U("Cate/updateOneField")}>',
                               data: "field=tj_book&value="+params.value+'&id='+params.pk,
                               success: function(msg){
                                   if(msg == 'success'){
                                       swal({title:"别名修改成功",text:"",type:"success"});
                                       return d.resolve();
                                   }else{
                                       swal("保存失败,请稍后在试","","error");
                                       return d.reject();
                                   }
                               }
                            });
                            return d.promise();
                       }
               }
            }],
            onClickRow: function(row,$element,field){
                $('.success').removeClass('success');
                $($element).addClass('success');
            },
            onDblClickCell: function(field, value, row, $element){
                  if(field == 'alias'){
                      //$element.empty();
                      //$element.append("<input type='text' name='alias' value='' />");
                      //return '<input type="text" name="alias" value="" />';
                  }
            }
        });



    });
</script>